<template>
    <view>
        <image class="back" src="../../static/images/jpg01.jpg" mode="widthFix"></image>
        <view class="main">
            <view class="login">
                <view class="h1">选择国家</view>
                <view class="form">
                    <view class="select" @click="show = true">
                        <input placeholder="请选择国家" v-model="address.name">
                        <image src="../../static/images/icon09.png"></image>
                    </view>
                    <view class="btn" @click="submit">提交</view>
                </view>
            </view>
        </view>
        <u-picker
            :show="show"
            :columns="columns"
            @close="show = false"
            @cancel="show = false"
            @confirm="confirm"
            keyName="name"
        ></u-picker>
    </view>
</template>

<script>
    import {
        getMeAddress, userInfo
    } from '../../api/api'
    export default {
        data() {
            return {
                show:false,
                columns:[],
                address:'',
            }
        },
        onLoad() {
            this.getMeAddressFun();
            console.log(this.$menu);
        },
        methods: {
            submit(){
                if(!this.address){
                    return uni.showToast({
                        title:'请选择国家',
                        icon:'none'
                    })
                }
                uni.setStorageSync('addressId',this.address.id);
                userInfo().then(res => {
                    uni.setStorageSync('userInfo',res.data);
                    this.$common.go(3,`/pages/index/index`);
                })

            },
            getMeAddressFun(){
                getMeAddress().then(res => {
                    this.columns.push(res.data);
                })
            },
            confirm(e){
                this.show = false;
                this.address = e.value[0];
            }
        }
    }
</script>
<style>
    page{
        background: #f5f5f5;
    }
</style>
<style lang="scss" scoped>
    .back{
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
    }
    .main{
        width: 100%;
        height: 100vh;
        position: relative;
        z-index: 2;
        display: flex;
        align-items: center;
        justify-content: center;
        .login{
            width: 640rpx;
            .h1{
                font-size: 45rpx;
                color: #222;
                text-align: center;
            }
            .form{
                padding-top: 65rpx;
                input{
                    width: 100%;
                    height: 100rpx;
                    border-radius: 100rpx;
                    background: #fff;
                    padding: 0 60rpx;
                    font-size: 30rpx;
                    color: #222;
                    box-sizing: border-box;
                    margin-top: 47rpx;
                }
                .select{
                    position: relative;
                    &:after{
                        content: '';
                        display: block;
                        width: 100%;
                        height: 100%;
                        position: absolute;
                        top: 0;
                        left: 0;
                        z-index: 2;
                    }
                    image{
                        width: 31rpx;
                        height: 18rpx;
                        transform: translateY(-50%);
                        position: absolute;
                        top: 50%;
                        right: 60rpx;
                    }
                }
                .btn{
                    height: 100rpx;
                    border-radius: 100rpx;
                    background: #f00;
                    text-align: center;
                    line-height: 100rpx;
                    font-size: 36rpx;
                    color: #fff;
                    margin-top: 100rpx;
                    background: #365aa6;
                }
            }
        }
    }
</style>
